﻿using System;
using System.Collections.Generic;
using System.IO;
using ProjScan.Config;

namespace ProjScan.Tools
{
	// Token: 0x02000176 RID: 374
	internal class WhiteAssetManager
	{
		// Token: 0x06000D2E RID: 3374 RVA: 0x00006B2F File Offset: 0x00004D2F
		private WhiteAssetManager()
		{
		}

		// Token: 0x06000D2F RID: 3375 RVA: 0x00006B4F File Offset: 0x00004D4F
		public void Init()
		{
			this.dicWhiteList = new Dictionary<string, List<string>>();
			this.path = Path.Combine(ToolsHelper.GetLocationPath(), "whiteList.csv");
			this.LoadWhiteList();
		}

		// Token: 0x06000D30 RID: 3376 RVA: 0x0003ACC0 File Offset: 0x00038EC0
		public void AddEntry(string string_1, string string_2)
		{
			List<string> list = new List<string>();
			bool flag = this.dicWhiteList.ContainsKey(string_1);
			if (flag)
			{
				list = this.dicWhiteList[string_1];
				bool flag2 = !list.Contains(string_2);
				if (flag2)
				{
					list.Add(string_2);
				}
				this.dicWhiteList[string_1] = list;
			}
			else
			{
				list.Add(string_2);
				this.dicWhiteList.Add(string_1, list);
			}
			this.UpdateListFile();
		}

		// Token: 0x06000D31 RID: 3377 RVA: 0x0003AD3C File Offset: 0x00038F3C
		private void UpdateListFile()
		{
			bool flag = !File.Exists(this.path);
			if (flag)
			{
				File.Create(this.path);
			}
			using (StreamWriter streamWriter = new StreamWriter(this.path))
			{
				string value = "\"RuleID\",\"AssetPath\",";
				streamWriter.WriteLine(value);
				foreach (string string_ in this.dicWhiteList.Keys)
				{
					this.WriteEntries(string_, streamWriter);
				}
				streamWriter.Flush();
				streamWriter.Close();
			}
		}

		// Token: 0x06000D32 RID: 3378 RVA: 0x0003AE00 File Offset: 0x00039000
		private void WriteEntries(string string_1, StreamWriter streamWriter_0)
		{
			bool flag = this.dicWhiteList.ContainsKey(string_1);
			if (flag)
			{
				foreach (string str in this.dicWhiteList[string_1])
				{
					string value = string_1 + "," + ToolsHelper.QuoteString(str);
					streamWriter_0.WriteLine(value);
				}
			}
		}

		// Token: 0x06000D33 RID: 3379 RVA: 0x0003AE84 File Offset: 0x00039084
		private void LoadWhiteList()
		{
			string text = "RuleID";
			string text2 = "AssetPath";
			List<Dictionary<string, string>> list = CSVUtils.ReadCsvFile(this.path, text, text2, "Loading CSV", "Loading CS....");
			bool flag = list != null;
			if (flag)
			{
				foreach (Dictionary<string, string> dictionary in list)
				{
					string key = string.Empty;
					string item = string.Empty;
					bool flag2 = dictionary.ContainsKey(text);
					if (flag2)
					{
						key = dictionary[text];
					}
					bool flag3 = dictionary.ContainsKey(text2);
					if (flag3)
					{
						item = dictionary[text2];
					}
					bool flag4 = this.dicWhiteList.ContainsKey(key);
					if (flag4)
					{
						bool flag5 = !this.dicWhiteList[key].Contains(item);
						if (flag5)
						{
							this.dicWhiteList[key].Add(item);
						}
					}
					else
					{
						List<string> list2 = new List<string>();
						list2.Add(item);
						this.dicWhiteList.Add(key, list2);
					}
				}
			}
			this.LoadQAOnlineWhiteList();
		}

		// Token: 0x06000D34 RID: 3380 RVA: 0x0003AFC0 File Offset: 0x000391C0
		private void LoadQAOnlineWhiteList()
		{
			for (int i = 0; i < Singleton<QAOnlineSettings>.Instance.RuleIdList.Length; i++)
			{
				string text = Singleton<QAOnlineSettings>.Instance.RuleIdList[i];
				List<string> whiteList = Singleton<QAOnlineSettings>.Instance.GetWhiteList(text);
				bool flag = whiteList == null || whiteList.Count == 0;
				if (!flag)
				{
					List<string> list;
					bool flag2 = this.dicWhiteList.TryGetValue(text, out list);
					if (flag2)
					{
						list.AddRange(whiteList);
					}
					else
					{
						this.dicWhiteList[text] = new List<string>(whiteList);
					}
				}
			}
		}

		// Token: 0x06000D35 RID: 3381 RVA: 0x0003B058 File Offset: 0x00039258
		public List<string> GetWhiteListForRuleId(string ruleId)
		{
			List<string> result = new List<string>();
			bool flag = this.dicWhiteList.ContainsKey(ruleId);
			if (flag)
			{
				result = this.dicWhiteList[ruleId];
			}
			return result;
		}

		// Token: 0x06000D36 RID: 3382 RVA: 0x0003B090 File Offset: 0x00039290
		public void ReplaceRuleList(string string_1, List<string> list_0)
		{
			bool flag = this.dicWhiteList.ContainsKey(string_1);
			if (flag)
			{
				this.dicWhiteList[string_1] = list_0;
				this.UpdateListFile();
			}
		}

		// Token: 0x04000805 RID: 2053
		public Dictionary<string, List<string>> dicWhiteList = new Dictionary<string, List<string>>();

		// Token: 0x04000806 RID: 2054
		public static readonly WhiteAssetManager Instance = new WhiteAssetManager();

		// Token: 0x04000807 RID: 2055
		private string path = "";
	}
}
